# Python操作MySQL
import pymysql

# 建立连接
conn = pymysql.connect(host='master', port=3306, user='root', password='123456', db='db1')
# 创建一个游标cursor
cursor = conn.cursor()
# 执行SQL
cursor.execute("select * from stu")
# 获取数据
# print(cursor.fetchone())
# print(cursor.fetchmany(2))
print(cursor.fetchall())
# 插入数据
sid = '001'
sname = '张三'
cid = '02'
cursor.execute("insert into stu values(%s,%s,%s)", (sid, sname, cid))
# 需要手动提交
conn.commit()
# 关闭连接
cursor.close()
conn.close()
